//
//  InfoVerify.m
//  ChampoinPeso
//
//  Created by mac on 2025/2/20.
//

#import "InfoVerify.h"
#import "SelectPop.h"
@interface InfoVerify()<UITextFieldDelegate>
@property (nonatomic,strong)UIView *fullNameView;

@property (nonatomic,strong)UIView *idNoView;

@property (nonatomic,strong)UIView *birthdayView;


@end
@implementation InfoVerify

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */
-(void)setStr:(NSString *)str
{
    self.fullName.text = str;
}
-(void)setStr1:(NSString *)str
{
    self.idNo.text = str;
}
-(void)setStr2:(NSString *)str
{
    self.birthday.text = str;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
-(void)setupUI
{
    UIView *view = [UIView new];
    [self addSubview:view];
    view.backgroundColor = UIColor.clearColor;
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_offset(0);
        make.height.mas_equalTo(445);
    }];
    UIImageView *bgIV = [[UIImageView alloc] initWithFrame:self.bounds];
    bgIV.image = [UIImage imageNamed:@"idtype_sbg"];
    [self addSubview:bgIV];
    [self sendSubviewToBack:bgIV];
    [bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_offset(0);
        make.bottom.mas_offset(-50);
    }];
    UILabel *name = [UILabel new];
    name.text = @"Confirm information";
    name.textColor = HexColor(@"#212121");
    name.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
    [view addSubview:name];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(25);
        make.centerX.mas_equalTo(view);
    }];
    [view addSubview:self.fullNameView];
    [_fullNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(name.mas_bottom).offset(28);
        make.left.mas_offset(17);
        make.right.mas_offset(-17);
    }];
    [view addSubview:self.idNoView];
    [_idNoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_fullNameView.mas_bottom).offset(8);
        make.left.mas_offset(17);
        make.right.mas_offset(-17);
    }];
    [view addSubview:self.birthdayView];
    [_birthdayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_idNoView.mas_bottom).offset(8);
        make.left.mas_offset(17);
        make.right.mas_offset(-17);
    }];
    UILabel *l = [UILabel new];
    l.textColor  = HexColor(@"#FFA004");
    l.text = @"Check the identity information andmake sure it is correct, oncesubmitted it cannot be changed!";
    l.numberOfLines = 0;
    l.font = [UIFont systemFontOfSize:12];
    [view addSubview:l];
    [l mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_birthdayView.mas_bottom).offset(8);
        make.left.mas_offset(17*2);
        make.right.mas_offset(-17*2);
    }];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"pop_turn"] forState:UIControlStateNormal];
    [view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(16);
        make.right.bottom.mas_offset(-16);
        make.height.mas_equalTo(50);
    }];
    
    UIButton *close = [UIButton buttonWithType:UIButtonTypeCustom];
    [close setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
    [self addSubview:close];
    [close mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(view.mas_bottom).offset(20);
        make.centerX.mas_equalTo(self);
        make.bottom.mas_offset(-20);
    }];
    
    [close addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
    [btn addTarget:self action:@selector(apply) forControlEvents:UIControlEventTouchUpInside];

}
-(void)close
{
    if (self.closeAction) {
        self.closeAction();
    }}
-(void)apply
{
    if(self.commitAction) {
        self.commitAction(self.fullName.text, self.idNo.text, self.birthday.text);
    }
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (textField == self.birthday) {
        [self endEditing:YES];
        [[SelectPop getInstance] dateSelect];
        [SelectPop getInstance].dateCommitAction = ^(NSString * _Nonnull res) {
            self.birthday.text = res;
        } ;
        return NO;
    }
    return YES;
}

-(UIView *)fullNameView
{
    if (!_fullNameView) {
        _fullNameView = [UIView new];
        UIView *view = [UIView new];
        view.backgroundColor = UIColor.clearColor;
        [_fullNameView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.mas_offset(0);
        }];
        UILabel *lab = [UILabel new];
        lab.text = @"Full Name";
        lab.textColor = DetailColor;
        lab.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
        [view addSubview:lab];
        [lab  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(17);
            make.top.mas_offset(0);
        }];
        UIView *bview = [UIView new];
        bview.backgroundColor = UIColor.whiteColor;
        bview.layer.cornerRadius = 8;
        [view addSubview:bview];
        [bview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(17);
            make.right.mas_offset(-17);
            make.top.equalTo(lab.mas_bottom).offset(6);
            make.height.mas_equalTo(48);
            make.bottom.mas_offset(0);
        }];
        [bview addSubview:self.fullName];
        [_fullName mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(13);
            make.right.mas_offset(-13);
            make.top.bottom.mas_offset(0);
        }];
    }
    return _fullNameView;
}

-(UITextField *)fullName
{
    if (!_fullName) {
        _fullName = [UITextField new];
        _fullName.delegate = self;
        _fullName.textColor = HexColor(@"#212121");
        _fullName.font = [UIFont systemFontOfSize:18 weight:UIFontWeightBold];
    }
    return _fullName;
}

-(UIView *)idNoView
{
    if (!_idNoView) {
        _idNoView = [UIView new];
        UIView *view = [UIView new];
        view.backgroundColor = UIColor.clearColor;
        [_idNoView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.mas_offset(0);
        }];
        UILabel *lab = [UILabel new];
        lab.text = @"ID NO.";
        lab.textColor = DetailColor;
        lab.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
        [view addSubview:lab];
        [lab  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(17);
            make.top.mas_offset(0);
        }];
        UIView *bview = [UIView new];
        bview.backgroundColor = UIColor.whiteColor;
        bview.layer.cornerRadius = 8;
        [view addSubview:bview];
        [bview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(17);
            make.right.mas_offset(-17);
            make.top.equalTo(lab.mas_bottom).offset(6);
            make.height.mas_equalTo(48);
            make.bottom.mas_offset(0);
        }];
        [bview addSubview:self.idNo];
        [_idNo mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(13);
            make.right.mas_offset(-13);
            make.top.bottom.mas_offset(0);
        }];
    }
    return _idNoView;

}
-(UITextField *)idNo
{
    if (!_idNo) {
        _idNo = [UITextField new];
        _idNo.textColor = HexColor(@"#212121");
//        _idNo.keyboardType = UIKeyboardTypeNumberPad;
        _idNo.delegate = self;
        _idNo.font = [UIFont systemFontOfSize:18 weight:UIFontWeightBold];
    }
    return _idNo;

}
-(UITextField *)birthday
{
    if (!_birthday) {
        _birthday = [UITextField new];
        _birthday.textColor = HexColor(@"#212121");
        _birthday.delegate = self;
        _birthday.font = [UIFont systemFontOfSize:18 weight:UIFontWeightBold];
    }
    return _birthday;
}

-(UIView *)birthdayView
{
    if (!_birthdayView) {
        _birthdayView = [UIView new];
        UIView *view = [UIView new];
        view.backgroundColor = UIColor.clearColor;
        [_birthdayView addSubview:view];
        [view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.mas_offset(0);
        }];
        UILabel *lab = [UILabel new];
        lab.text = @"Birthday";
        lab.textColor = DetailColor;
        lab.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
        [view addSubview:lab];
        [lab  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(17);
            make.top.mas_offset(0);
        }];
        UIView *bview = [UIView new];
        bview.backgroundColor = UIColor.whiteColor;
        bview.layer.cornerRadius = 8;
        [view addSubview:bview];
        [bview mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(17);
            make.right.mas_offset(-17);
            make.top.equalTo(lab.mas_bottom).offset(6);
            make.height.mas_equalTo(48);
            make.bottom.mas_offset(0);
        }];
        [bview addSubview:self.birthday];
        [_birthday mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(13);
            make.right.mas_offset(-13);
            make.top.bottom.mas_offset(0);
        }];
    }
    return _birthdayView;

}
@end
